package com.njupt.towersusers.serivices.impl;

import com.njupt.towerscommons.PhotoUploadService;
import com.njupt.towersusers.domain.Drivers;
import com.njupt.towersusers.serivices.DriversService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;

@Service
@Transactional
public class DriversServiceImpl implements DriversService {
    @Resource
    private PhotoUploadService photoUploadService;
//    @Value("${imgPath}")
//    private String imgPath;
    @Value("imgPath")   //给属性imgPath注入，
    private String imgPath;

    @Override
    public void addDriver(Drivers driver, MultipartFile head, MultipartFile card) {
        //将用户传入的连个图形文件临时存放在Web服务器上存储为图像文件
        File headImg=new File(imgPath+"/"+head.getOriginalFilename());
        File driverImg=new File(imgPath+"/"+card.getOriginalFilename());
        try {
            head.transferTo(headImg);
            card.transferTo(driverImg);
        } catch (IOException e) {
            e.printStackTrace();
        }

        //将两个临时文件调用自己的服务类上传到文件服务器并返回文件信息
        //再把返回的文件信息存放到drivers对象中
        //将drivers对象存放到MySQL数据库中
    }
}
